package com.zidongxiangxi.lock.starter.aop;

import com.zidongxiangxi.lock.starter.annotation.Locking;
import org.aopalliance.aop.Advice;
import org.springframework.aop.Pointcut;
import org.springframework.aop.support.AbstractPointcutAdvisor;
import org.springframework.aop.support.annotation.AnnotationMatchingPointcut;

import javax.validation.constraints.NotNull;

/**
 * LockAnnotationAdvisor
 *
 * @author chenxudong
 * @since 2021/2/22 9:47
 */
public class LockAnnotationAdvisor extends AbstractPointcutAdvisor {

    private final Advice advice;

    private final Pointcut pointcut = new AnnotationMatchingPointcut(null, Locking.class, true);

    public LockAnnotationAdvisor(@NotNull DistributedLockInterceptor interceptor, int order) {
        this.advice = interceptor;
        setOrder(order);
    }

    @Override
    public Pointcut getPointcut() {
        return this.pointcut;
    }

    @Override
    public Advice getAdvice() {
        return this.advice;
    }
}
